﻿
using com.iot.core.annotation;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using com.iot.core.ext;
using System.ComponentModel.DataAnnotations;

namespace com.iot.core.data
{
    [Schema(Name = "分页查询类", Description = "")]
    public   class BasePageQto:BaseQto
    {
        public string Key { get; set; } = "";
        [Range(1,int.MaxValue)]
        public int Page { get; set; } = 1  ;
        [Range(1, int.MaxValue)]
        public int PageSize { get; set; } = 10 ;

        public string SortFields { get; set; } = "";

         
        public Sort GetSort()
        {
            if (string.IsNullOrEmpty(SortFields))
            {
                var r = new Sort();             
                return r;
            }
            var arr = SortFields.Split( new char[] { ',' },StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length == 0)
            {
                var r = new Sort();
                return r;
            }
            var arr2 = arr[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr2.Length != 2)
            {
                var r = new Sort();
                return r;
            }

            {
                arr2[1] = arr2[1].ToLower();
                var r = new Sort();
                r.Filed=arr2[0].Trim().ToUpperCamelCase();
                r.Asc = "asc".Equals(arr2[1]);                     
                return r;

            }
        }

    }
}
